package com.example.demo.util;

import org.jasypt.encryption.pbe.PooledPBEStringEncryptor;
import org.jasypt.encryption.pbe.config.SimpleStringPBEConfig;

public class JasyptUtil {
    
    public static void main(String[] args) {
        PooledPBEStringEncryptor encryptor = new PooledPBEStringEncryptor();
        SimpleStringPBEConfig config = new SimpleStringPBEConfig();
        config.setPassword("iux8jj%112");
        config.setAlgorithm("PBEWithMD5AndDES");
        config.setKeyObtentionIterations("1000");
        config.setPoolSize("1");
        config.setProviderName("SunJCE");
        config.setSaltGeneratorClassName("org.jasypt.salt.RandomSaltGenerator");
        config.setStringOutputType("base64");
        encryptor.setConfig(config);
        
        // 加密数据库密码
        String encryptedPassword = encryptor.encrypt("stork%sfxQA12");
        System.out.println("加密后的数据库密码: ENC(" + encryptedPassword + ")");
        
        // 解密测试
        String decryptedPassword = encryptor.decrypt(encryptedPassword);
        System.out.println("解密后的数据库密码: " + decryptedPassword);
    }
} 